#!/usr/bin/env python3
import pickle
import json

def load_result_pkl(result_path):
    """加载result.pkl文件"""
    with open(result_path, 'rb') as f:
        results = pickle.load(f)
    return results

def load_coco_annotations(annotation_path):
    """加载COCO格式的标注数据"""
    with open(annotation_path, 'r') as f:
        annotations = json.load(f)
    return annotations

# 加载数据
results = load_result_pkl('/disk2/xd/project/mmdetection/work_dirs/visual/result.pkl')
annotations = load_coco_annotations('/disk2/xd/project/mmdetection/data/coco/annotations/instances_val2017.json')

print("预测结果结构:")
print(f"类型: {type(results)}")
print(f"长度: {len(results)}")
if len(results) > 0:
    print(f"第一个元素类型: {type(results[0])}")
    print(f"第一个元素键: {list(results[0].keys())}")
    if 'pred_instances' in results[0]:
        pred_inst = results[0]['pred_instances']
        print(f"pred_instances类型: {type(pred_inst)}")
        print(f"pred_instances属性: {dir(pred_inst)}")

print("\n标注数据结构:")
print(f"类型: {type(annotations)}")
print(f"键: {list(annotations.keys())}")
print(f"annotations长度: {len(annotations['annotations'])}")
print(f"images长度: {len(annotations['images'])}")
print(f"categories长度: {len(annotations['categories'])}")

if len(annotations['annotations']) > 0:
    print(f"第一个标注: {annotations['annotations'][0]}")
if len(annotations['images']) > 0:
    print(f"第一个图像: {annotations['images'][0]}")
if len(annotations['categories']) > 0:
    print(f"第一个类别: {annotations['categories'][0]}") 